package com.tmeone.erpone.controller;




import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.TLogistics;
import com.tmeone.erpone.service.ITLogisticsService;
import com.tmeone.erpone.service.TLogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.UUID;

@RestController
public class TLogisticsController {
    @Autowired
    private TLogisticsService logisticsService;
    @Autowired
    ITLogisticsService logisticsService1;

    @GetMapping("/logistics1")
    public JsonResult logistics() {
        return new JsonResult(1,logisticsService1.getLogistics());
    }

    //分页
    @GetMapping("logistics")
    public JsonResult getPageLogistics(@RequestParam(value = "current",required = false,defaultValue = "1")Integer current,
                                       @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize){
        Page<TLogistics> logistics = new Page<>(current,pageSize);
     return new JsonResult(1,logisticsService.getPageTLogistics(logistics));
    }

    //添加
    @PostMapping("logistics")
    public JsonResult addLogistics(@RequestBody TLogistics logistics){
        logistics.setLogisticsId(UUID.randomUUID().toString().replace("-","").substring(0,10));
        return  new JsonResult(1,logisticsService.save(logistics));
    }
    //修改
    @PutMapping("logistics")
    public JsonResult updateLogistics(@RequestBody TLogistics logistics){
        return new JsonResult(1,logisticsService.updateById(logistics));
    }
    //删除
    @DeleteMapping("logistics/{id}")
    public JsonResult deleteLogistics(@PathVariable String id){
        return new JsonResult(1,logisticsService.removeById(id));
    }

    //查询公司名称
    @GetMapping("logistic")
    public JsonResult selectOne(String username,Integer curr,Integer pageSize){
        Page<TLogistics> logisticsPage = new Page<>(1,pageSize);
        return new JsonResult(1,logisticsService.pageUserName(logisticsPage,username));
    }

    //查公司的价格
    @GetMapping("priceDisplay")
    public JsonResult showPriceDisplay(String uname){
        List<TLogistics> list1 = logisticsService.list(new QueryWrapper<TLogistics>().lambda().eq(TLogistics::getLogisticsId, uname));
        return new JsonResult(1,list1);
    }

}
